package com.yuntsg.nnsfcp.controller.front;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.yuntsg.nnsfcp.common.beans.ResultBean;
import com.yuntsg.nnsfcp.common.utils.CheckUtil;
import com.yuntsg.nnsfcp.common.utils.StringUtil;
import com.yuntsg.nnsfcp.common.utils.UserUtil;
import com.yuntsg.nnsfcp.entity.ArticleSearchVo;
import com.yuntsg.nnsfcp.front.entity.PmUtAidInfoNsfcHosp;
import com.yuntsg.nnsfcp.front.mapper.PmUtAidInfoNsfcHospMapper;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/his-fund-search")
@RestController
//@Api(tags = "历史基金论文检索", description = "历史基金论文检索")
@Slf4j
public class HisFundController {

    // 未来学习中心的
    public static String RESTURL_ES = "http://10.1.1.11:29000";
    @Resource
    UserUtil userUtil;

    @Resource
    PmUtAidInfoNsfcHospMapper pmUtAidInfoNsfcHospMapper;

    @PostMapping(value = "search")
//    @ApiOperation(value = "1基金论文检索")
    public ResultBean<Object> search(@RequestBody ArticleSearchVo articleSearchVo) {
        log.info("articleSearchVo+" + articleSearchVo);
        Integer uid = userUtil.getFrontUid();
        Integer gid = userUtil.getFrontGid();
        String uname = userUtil.getFrontUname();
//        if (StringUtil.isNull(articleSearchVo.getPram())) {
//            articleSearchVo.setPram("TGF BETA");
//        }
        articleSearchVo.setUid(uid);
        articleSearchVo.setGid(gid);
        articleSearchVo.setRealName(uname);
        String post = HttpUtil.post(RESTURL_ES + "/search/search-nsfc", JSONObject.toJSONString(articleSearchVo));
        JSONObject jsonObject = JSONObject.parseObject(post);
        JSONObject data = jsonObject.getJSONObject("data");
        return new ResultBean<>(data);
    }

    @GetMapping(value = "search-detail")
//    @ApiOperation(value = "2基金论文检索详情页 传递id")
    public ResultBean<Object> searchDetail(Integer id) {
        CheckUtil.check(StringUtil.isNotNull(id), "id is not null");
        PmUtAidInfoNsfcHosp pmUtAidInfoNsfcHosp = pmUtAidInfoNsfcHospMapper.selectById(id);
        return new ResultBean<>(pmUtAidInfoNsfcHosp);
    }


}
